/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package todotask;

import javax.swing.*;
import java.awt.*;

public class BackgroundPanel extends JPanel {

    Image image;

    public BackgroundPanel(Boolean isSelected) {
        setImageBackground(isSelected);
    }

    public void setImageBackground(Boolean isSelected) {
        try {
            if (isSelected) {
                image = (new ImageIcon(getClass().getResource("images/selected.png"))).getImage();
            } else {
                image = (new ImageIcon(getClass().getResource("images/background.png"))).getImage();
            }
        } catch (Exception e) {/*handled in paintComponent()*/
            e.printStackTrace();
        }
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (image != null) {
            int uno = (this.getWidth() / 2) - (image.getWidth(this) / 2);
            int dos = (this.getHeight() / 2) - (image.getHeight(this) / 2);
            g.drawImage(image, uno, dos, image.getWidth(this), image.getHeight(this), this);
            //(image,location x, location y, size x, size y)
        }
    }
}
